import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver,AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        AntDesignVueResolver({
          importStyle: false // css in js
        })
      ],
      template: {
        script: {
          lang: 'js',
          setup: true
        },
        style: {
          lang: 'scss',
          scoped: true
        }
      }
    })
  ],

  // css: {
  //   preprocessorOptions: {
  //     scss: { api: 'modern-compiler' },
  //   }
  // },
  //http://localhost:5173/api/users → http://10.21.121.225:9091/users
  server: {
    proxy: {
      '/api': {
        // 以 /api 开头的请求
        target: 'http://10.21.221.112:9091/api', // 目标服务器地址
        changeOrigin: true, // 修改请求头中的 Origin
        rewrite: (path) => path.replace(/^\/api/, '') // 可选路径重写
      }
    }
  },
  base: '/', // vite 中的环境变量 import.meta.env.BASE_URL  就是 vite.config.js 中的 base 配置项
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)) // 起别名:设置 `@` 指向 `src` 目录
    }
  }
})
